

#include "ThreadPool.hpp"

void test_threads_pool()
{
    ENABLE_SCREEN();
    srand((unsigned)time(nullptr));

    // std::unique_ptr<ThreadPool<func_t>> tp = std::make_unique<ThreadPool<func_t>>(5);
    // ThreadPool<Task> *tp = new ThreadPool<Task>(9);


    // ThreadPool<Task>::GetInstance()->Init(); // 初始化线程池
    // LOG(INFO, "Init Success");
    // cout << "Init Success" << endl;
    // ThreadPool<Task>::GetInstance()->Start(); // 线程池开始运行
    // LOG(INFO, "Start success");

    // cout << "Start success" << endl;

    int cnt = 8;
    while (cnt--)
    {
        LOG(INFO, "Start push Tasks");
        // cout << "Start push Tasks" << endl;

        int x = (rand() ^ getpid()) % 17;
        usleep(x * 1000);
        int y = (rand() ^ getpid()) % 17;
        Task t(x, y);
        
        ThreadPool<Task>::GetInstance()->PushTask(t);

        // cout << "cnt : " << cnt << endl;
        LOG(INFO, "%d", cnt);

        sleep(1);
    }

    ThreadPool<Task>::GetInstance()->Stop();
    sleep(2);
}

void test_log()
{
    // Log lg(FILE_TYPE,"log.txt");
    // lg.load_message(1,__FILE__,__LINE__,"This is a test massage %d %s %f\n",10,"hehe",9.8234);
    // LOG(DEBUG, "hello \n");
}

int main()
{
    // test_log();
    test_threads_pool();
    return 0;
}